package form;

import java.awt.Dimension;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

import checker.StringChecker;

public abstract class FormInputComponent extends JPanel{

	private JLabel label;
	protected JComponent component;
	private StringChecker inputChecker;
	private Dimension dimension;
	 
	protected FormInputComponent(String label, JComponent component, StringChecker inputChecker){
		if(label != null)
		this.label = new JLabel(label);
		this.component = component;
		this.inputChecker = inputChecker;
		

		addComponents();
	
		dimension = new Dimension(250,35);
		this.setMinimumSize(dimension);
		this.setMaximumSize(dimension);		
	}
	
	public Dimension getDimension() {
		return dimension;
	}
	
	public JComponent getInputComponent(){
		return component;
	}

	private void addComponents(){
		if(label != null)
			add(label);
		if(component != null)
			add(component);
	}
	
	public boolean hasValidInput() {
		if(inputChecker != null)
			return inputChecker.getErrorMsg(getInput().toString()).equals("");
		return true;
	}
	
	public String getErrorMsg() {
		if(inputChecker != null)
			return label.getText()+" "+inputChecker.getErrorMsg(getInput().toString());
		return "";
	}
	
	public void enableInput() {
		component.setEnabled(true);
	}

	public void disableInput() {
		component.setEnabled(false);
	}
	
	public abstract void returnUIToDefaultState();
	public abstract void clearUIError();
	public abstract void triggerUIError();
	public abstract String getInput();
	public abstract void setInput(String input);
	

	
}

